package com.heima.wemedia.controller.v1;

import com.heima.apis.article.IArticleClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.*;
import com.heima.utils.thread.WmThreadLocalUtil;
import com.heima.wemedia.service.WmCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:Dikk
 * @create: 2023-08-03 10:00
 * @Description: WmCommentController
 */
@RestController
@RequestMapping("/api/v1/comment/manage")
public class WmCommentController {

    @Autowired
    private WmCommentService commentService;

    @Autowired
    private IArticleClient articleClient;

    /**
     * 查询评论列表
     *
     * @param wmCommentPageReqDTO
     * @return
     */
    @PostMapping("/find_news_comments")
    public ResponseResult findNewsComments(@RequestBody WmCommentPageReqDTO wmCommentPageReqDTO) {
        return commentService.findNewsComments(wmCommentPageReqDTO);
    }


    /**
     * 更新文章的评论状态
     *
     * @param wmCommentUpdateStatusDTO
     * @return
     */
    @PostMapping("/update_comment_status")
    public ResponseResult updateCommentStatus(@RequestBody WmCommentUpdateStatusDTO wmCommentUpdateStatusDTO) {
        return articleClient.updateCommentStatus(wmCommentUpdateStatusDTO);
    }

    /**
     * 查看文章评论详情
     *
     * @param wmCommentDetailPageReqDTO
     * @return
     */
    @PostMapping("/list")
    public ResponseResult commentDetailList(@RequestBody WmCommentListPageReqDTO wmCommentDetailPageReqDTO) {
        return articleClient.commentList(wmCommentDetailPageReqDTO);
    }

    /**
     * 自媒体端评论点赞
     *
     * @param wmCommentLikeDTO
     * @return
     */
    @PostMapping("/like")
    public ResponseResult commentLike(@RequestBody WmCommentLikeDTO wmCommentLikeDTO) {
        Integer authorId = WmThreadLocalUtil.getUser().getId();
        return articleClient.commentLike(wmCommentLikeDTO, authorId);
    }

    /**
     * 自媒体端回复评论
     *
     * @param wmCommentRepayDTO
     * @return
     */
    @PostMapping("/comment_repay")
    public ResponseResult commentRepay(@RequestBody WmCommentRepayDTO wmCommentRepayDTO) {
        return commentService.commentRepay(wmCommentRepayDTO);
    }

    /**
     * 删除评论
     *
     * @param commentId
     * @return
     */
    @DeleteMapping("/del_comment/{commentId}")
    public ResponseResult deleteComment(@PathVariable("commentId") String commentId) {
        return commentService.deleteComment(commentId);
    }

    /**
     * 删除评论回复
     *
     * @param commentRepayId
     * @return
     */
    @DeleteMapping("/del_comment_repay/{commentRepayId}")
    public ResponseResult deleteCommentRepay(@PathVariable("commentRepayId") String commentRepayId) {
        return commentService.deleteCommentRepay(commentRepayId);
    }
}
